package com.ellricky.baselib.dialog.picker;

import android.app.Activity;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;

import com.andr.common.util.EmptyUtil;
import com.andr.common.util.KeyboardUtil;
import com.andr.common.util.ResUtil;
import com.andr.common.util.ToastUtil;
import com.andr.common.util.date.TimeUtil;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.ellricky.baselib.R;
import com.ellricky.baselib.cache.LocalCacheUtil;
import com.ellricky.baselib.dialog.picker.consultant.ETimePickerBuilder;
import com.ellricky.baselib.dialog.picker.consultant.ETimePickerView;
import com.ellricky.baselib.entity.IdNamePickerEntity;
import com.ellricky.baselib.http.Api;
import com.ellricky.baselib.http.HttpUtils;
import com.ellricky.baselib.http.callback.EListCallback;
import com.ellricky.baselib.util.EAppUtil;
import com.ellricky.baselib.util.NewEListCallback;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class EPickerUtil {
    private Activity mContext;
    private int mPicType;

    public EPickerUtil(Activity context) {
        mContext = context;
    }


///////////////////////////////////////////////////////////////////////////
//  String 类型
///////////////////////////////////////////////////////////////////////////

    private OptionsPickerView<String> strPicker;
    private List<String> strList;

    public void showLinePicker(int pickCurPos, final EPickerStrListener listener) {
        String[] arr = ResUtil.getStrArr(mContext, R.array.base_standard_line);
        showStrPicker(Arrays.asList(arr), EPickerType.PICK_LINE, pickCurPos, listener);
    }

    public void showMarketAgePicker(int pickCurPos, final EPickerStrListener listener) {
        String[] ages = ResUtil.getStrArr(mContext, R.array.base_market_age_list);
        showStrPicker(Arrays.asList(ages), EPickerType.PICK_AGE, pickCurPos, listener);
    }


    public void showTmTaskTypePicker(int pickCurPos, final EPickerStrListener listener) {
        String[] typeArr = ResUtil.getStrArr(mContext, R.array.base_act_type);
        showStrPicker(Arrays.asList(typeArr), EPickerType.PICK_ACT_TYPE, pickCurPos, listener);
    }

    public void showClueStateTypePicker(int pickCurPos, final EPickerStrListener listener) {
        String[] typeArr = ResUtil.getStrArr(mContext, R.array.base_clue_state);
        showStrPicker(Arrays.asList(typeArr), EPickerType.PICK_CLUE_STATE, pickCurPos, listener);
    }

    private void showStrPicker(List<String> dataList, int pickType, int pickCurPos, final EPickerStrListener listener) {
        strList = dataList;
        this.mPicType = pickType;
        if (strPicker == null) {
            strPicker = new OptionsPickerBuilder(mContext, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    if (listener != null) {
                        listener.onSelectItem(strList.get(options1), options1, mPicType);
                    }
                }
            })
                    .setCancelColor(Color.BLACK)
                    .setSubmitColor(Color.BLACK)
                    .setTitleBgColor(Color.WHITE)
                    .build();
        }
        if (strPicker.isShowing()) return;

        strPicker.setPicker(strList);

        int pointIndex = pickCurPos <= -1 ? 0 : pickCurPos;
        strPicker.setSelectOptions(pointIndex);
        strPicker.show();

    }


////////////////////////////////ƒ///////////////////////////////////////////
//  日期选择
///////////////////////////////////////////////////////////////////////////

    private int TIME_FORMAT_DATE = 1;
    private int TIME_FORMAT_HM = 2;
    private int TIME_FORMAT_MM = 3;
    private int TIME_FORMAT_MN = 4;
    private int TIME_FORMAT_DD = 5;

    public void showReservePicker(String picCurTime, final EPickerStrListener listener) {
        showTimePicker2(picCurTime, listener);
    }

    public void showBirthTimePicker(String picCurTime, final EPickerStrListener listener) {
        showDatePicker(EPickerType.PICK_BIRTH_DATE, picCurTime, listener);
    }


    public void showStartDatePicker(String picCurTime, final EPickerStrListener listener) {
        showDatePicker(EPickerType.PICK_START_DATE, picCurTime, listener);
    }

    public void showEndDatePicker(String picCurTime, final EPickerStrListener listener) {
        showDatePicker(EPickerType.PICK_END_DATE, picCurTime, listener);
    }


    public void showStartTimePicker(String picCurTime, final EPickerStrListener listener) {
        showHmPicker(EPickerType.PICK_START_TIME, picCurTime, listener);
    }


    public void showEndTimePicker(String picCurTime, final EPickerStrListener listener) {
        showHmPicker(EPickerType.PICK_END_TIME, picCurTime, listener);
    }

    public void showMonthPicker(String picCurTime, final EPickerStrListener listener) {
        showMonthPicker(EPickerType.PICK_START_TIME, picCurTime, listener);
    }

    private void showHmPicker(final int pickType, String curTime, final EPickerStrListener listener) {
        showTimePicker(pickType, "", "", curTime, TIME_FORMAT_HM, listener);
    }

    public void showDayMnPicker(String picCurTime, final EPickerStrListener listener) {
        showDayPicker(EPickerType.PICK_START_TIME, picCurTime, listener);
    }

    public void showMonthMnPicker(String picCurTime, final EPickerStrListener listener) {
        showHnPicker(EPickerType.PICK_START_TIME, picCurTime, listener);
    }

    private void showHnPicker(final int pickType, String curTime, final EPickerStrListener listener) {
        showTimePicker(pickType, "", "", curTime, TIME_FORMAT_MN, listener);
    }

    private void showDayPicker(final int pickType, String curTime, final EPickerStrListener listener) {
        showTimePicker(pickType, "", "", curTime, TIME_FORMAT_DD, listener);
    }

    private void showMonthPicker(final int pickType, String curTime, final EPickerStrListener listener) {
        showTimePicker(pickType, "", "", curTime, TIME_FORMAT_MM, listener);
    }

    private void showDatePicker(final int pickType, String curTime, final EPickerStrListener listener) {
        showTimePicker(pickType, "", "", curTime, TIME_FORMAT_DATE, listener);
    }

    private void showTimePicker(final int pickType,
                                String startTime, String endTime, String curTime, final int timeFormat,
                                final EPickerStrListener listener) {
        this.mPicType = pickType;

        String timeF = "yyyy-MM-dd HH:mm:ss";
        if (timeFormat == TIME_FORMAT_DATE) {
            timeF = "yyyy-MM-dd";
        } else if (timeFormat == TIME_FORMAT_HM) {
            timeF = "HH:mm";
        } else if (timeFormat == TIME_FORMAT_MM) {
            timeF = "yyyy.MM";
        } else if (timeFormat == TIME_FORMAT_MN) {
            timeF = "yyyy-MM";
        } else if (timeFormat == TIME_FORMAT_DD) {
            timeF = "yyyy-MM-dd";
        }

        Date sDate = TimeUtil.parse(startTime, timeF);
        Calendar sCal = TimeUtil.getCalendar(sDate);
        /*if (sDate == null) {
            sCal.set(1990, 1, 1);
        }*/

        Date eDate = TimeUtil.parse(endTime, timeF);
        Calendar eCal = TimeUtil.getCalendar(eDate);
        /*if (eDate == null) {
            eCal.set(2099, 12, 31);
        }*/

        // 设置当前所选位置
        Calendar cDate = TimeUtil.getCalendar(
                TimeUtil.parse(curTime, timeF)
        );

        final String resultForamt = timeF;
        TimePickerBuilder builder = new TimePickerBuilder(mContext, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                if (listener != null) {
                    String chooseTime = TimeUtil.format(date, resultForamt);
                    listener.onSelectItem(chooseTime, -1, mPicType);
                }
            }
        }).setCancelColor(Color.BLACK).setSubmitColor(Color.BLACK).setTitleBgColor(Color.WHITE);

        if (sDate != null && eDate != null) {
            builder.setRangDate(sCal, eCal);
        }

        if (timeFormat == TIME_FORMAT_DATE) {
            builder.setType(new boolean[]{true, true, true, false, false, false});
        } else if (timeFormat == TIME_FORMAT_HM) {
            builder.setType(new boolean[]{false, false, false, true, true, false});
        } else if (timeFormat == TIME_FORMAT_MM) {
            builder.setType(new boolean[]{true, true, false, false, false, false});
        } else if (timeFormat == TIME_FORMAT_MN) {
            builder.setType(new boolean[]{true, true, false, false, false, false});
        } else if (timeFormat == TIME_FORMAT_DD) {
            builder.setType(new boolean[]{true, true, true, false, false, false});
        } else {
            builder.setType(new boolean[]{true, true, true, true, true, true});
        }
        builder.setLabel("", "", "", "", "", "");

        TimePickerView timePickerView = builder.build();
        timePickerView.setDate(cDate);
        timePickerView.show();
        KeyboardUtil.hide(mContext);

    }


    private void showTimePicker2(String curTime, final EPickerStrListener listener) {

        String timeF = "yyyy-MM-dd HH:mm";

        Date sDate = TimeUtil.parse("", timeF);
        Calendar sCal = TimeUtil.getCalendar(sDate);
        /*if (sDate == null) {
            sCal.set(1990, 1, 1);
        }*/

        Date eDate = TimeUtil.parse("", timeF);
        Calendar eCal = TimeUtil.getCalendar(eDate);
        /*if (eDate == null) {
            eCal.set(2099, 12, 31);
        }*/

        // 设置当前所选位置
        Calendar cDate = TimeUtil.getCalendar(
                TimeUtil.parse(curTime, timeF)
        );

        final String resultForamt = timeF;
        ETimePickerBuilder builder = new ETimePickerBuilder(mContext, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                if (listener != null) {
                    String chooseTime = TimeUtil.format(date, resultForamt);
                    listener.onSelectItem(chooseTime, -1, mPicType);
                }
            }
        }).setCancelColor(Color.BLACK).setSubmitColor(Color.BLACK).setTitleBgColor(Color.WHITE);

        if (sDate != null && eDate != null) {
            builder.setRangDate(sCal, eCal);
        }

        builder.setType(new boolean[]{true, true, true, true, true, false});
        builder.setLabel("", "", "", "", "", "");

        ETimePickerView timePickerView = builder.build();
        timePickerView.setDate(cDate);
        timePickerView.show();
        KeyboardUtil.hide(mContext);

    }

///////////////////////////////////////////////////////////////////////////
// 负责人选择
// 教室选择
///////////////////////////////////////////////////////////////////////////

    private List<IdNamePickerEntity> personList;
    private List<IdNamePickerEntity> classRoomList;
    private List<IdNamePickerEntity> classTypeList;
    private List<IdNamePickerEntity> weekDayList;
    private List<IdNamePickerEntity> stuVipList;
    private List<IdNamePickerEntity> classList;
    private List<IdNamePickerEntity> clueFromList;
    private List<IdNamePickerEntity> teaClassList;
    private List<IdNamePickerEntity> teaLeaveTypeList;
    private List<IdNamePickerEntity> teaTempList;
    private List<IdNamePickerEntity> wishList;
    private List<IdNamePickerEntity> fileList;
    private List<IdNamePickerEntity> classStateList;
    private List<IdNamePickerEntity> ctList;
    private List<IdNamePickerEntity> courseList;
    private List<IdNamePickerEntity> ageList;
    private List<IdNamePickerEntity> openDateList;
    private List<IdNamePickerEntity> clueStateList;
    private List<IdNamePickerEntity> schoolList;
    private List<IdNamePickerEntity> intentList;
    private List<IdNamePickerEntity> classWareList;
    private List<IdNamePickerEntity> classKindList;
    private List<IdNamePickerEntity> classNumberList;
    private List<IdNamePickerEntity> classDateList;
    private List<IdNamePickerEntity> classTempList;
    private List<IdNamePickerEntity> studentList;
    private List<IdNamePickerEntity> orderStateList;
    private List<IdNamePickerEntity> orderCheckStateList;
    private List<IdNamePickerEntity> customList;

    public void checkCourseTypePicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_COURSE_TYPE, curEntity, listener);
    }

    public void checkFilePicker(IdNamePickerEntity curEntity, String courseId, final EPickerEntityListener<IdNamePickerEntity> listener) {
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("id", courseId);
        postRequest(EPickerType.PICK_FILE, curEntity, paramMap, listener);
    }

    public void checkCtPicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_CONSULTANT, curEntity, listener);
    }


    public void checkTeaClassPicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_TEACHER_CLASS, curEntity, listener);
    }

    public void checkTeaLeaveTypePicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_TEACHER_LEAVE_TYPE, curEntity, listener);
    }

    public void checkTeaTempPicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_TEMP_TEACHER, curEntity, listener);
    }

    public void checkClassPicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_CLASS, curEntity, listener);
    }

    public void checkStuVipPicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_VIP_STUDENT, curEntity, listener);
    }

    public void checkPersonPicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_ALL_PERSON, curEntity, listener);

    }

    public void checkClassRoomPicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_CLASS_ROOM, curEntity, listener);
    }

    public void checkAgePicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_AGE_RANGE, curEntity, listener);
    }

    public void checkOpenDate(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_OPEN_DATE, curEntity, listener);
    }

    public void checkSchoolDate(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_SCHOOL, curEntity, listener);
    }

    public void checkClassTypePicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_CLASS_TYPE, curEntity, listener);
    }

    public void checkClassStatePicker(String courseId, IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        HashMap<String, String> map = new HashMap<>();
        map.put("course_id", courseId);
        postRequest(EPickerType.PICK_CLASS_STATE, curEntity, map, listener);
    }

    public void checkStaffTypePicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_STUDENT_LIST, curEntity, listener);
    }

    public void checkClassWarePicker(String typeId, String stateId, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_CLASS_WARE, null, listener);
        String url = EAppUtil.getApiHost();
        HashMap<String, String> map = new HashMap<>();
        map.put("action", "ajaxfiles");
        map.put(" ware_course_type_id", typeId);
        map.put(" ware_stage_id", typeId);
    }

    public void checkClassWarePicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_CLASS_WARE, curEntity, listener);
    }

    public void checkClassWarePicker2(String typeId, String stateId, final EPickerEntityListener<IdNamePickerEntity> listener) {
        String url = EAppUtil.getManagerApiHost();
        HashMap<String, String> map = new HashMap<>();
        map.put("action", "ajaxfiles");
        map.put("ware_course_type_id", typeId);
        map.put("ware_stage_id", stateId);
        HttpUtils.getInstance().postFrom(url, map, new NewEListCallback<IdNamePickerEntity>(mContext) {
            @Override
            protected void onSuccess(List data, String msg) {
                if (data != null && data.size() > 0) {
                    // showDialog
                    classTempList = data;
                    showIdNamePicker(EPickerType.PICK_CLASS_TEMP, null, listener);
                }
            }
        });
    }

    public void checkClassDatePicker(IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(EPickerType.PICK_CLASS_DATE, curEntity, listener);
    }

    public void showClassTypePicker(List<IdNamePickerEntity> classTypeList, IdNamePickerEntity curEntity,
                                    final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.classTypeList = classTypeList;
        showIdNamePicker(EPickerType.PICK_CLASS_TYPE, curEntity, listener);
    }

    public void showWeekDayPicker(List<IdNamePickerEntity> weekDayList, IdNamePickerEntity curEntity,
                                  final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.weekDayList = weekDayList;
        showIdNamePicker(EPickerType.PICK_WEEK_DAY, curEntity, listener);
    }

    public void showClueFromPicker(List<IdNamePickerEntity> clueFromList, IdNamePickerEntity curEntity,
                                   final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.clueFromList = clueFromList;
        showIdNamePicker(EPickerType.PICK_CLUE_FROM, curEntity, listener);
    }

    public void showVisitWishPicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                    final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.wishList = list;
        showIdNamePicker(EPickerType.PICK_VISIT_WISH, curEntity, listener);
    }

    public void showClassStatePicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                     final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.classStateList = list;
        showIdNamePicker(EPickerType.PICK_CLASS_ATTEND_STATE, curEntity, listener);
    }

    public void showCustomPicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                 final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.customList = list;
        showIdNamePicker(EPickerType.PICK_CUSTOM, curEntity, listener);
    }

    public void showClassKindPicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                    final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.classKindList = list;
        showIdNamePicker(EPickerType.PICK_CLASS_KIND, curEntity, listener);
    }

    public void showClassNumberPicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                      final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.classNumberList = list;
        showIdNamePicker(EPickerType.PICK_CLASS_NUMBER, curEntity, listener);
    }

    public void showClueStatePicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                    final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.clueStateList = list;
        showIdNamePicker(EPickerType.PICK_CLUE_STATE, curEntity, listener);
    }

    public void showSchoolPicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                 final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.schoolList = list;
        showIdNamePicker(EPickerType.PICK_SCHOOL, curEntity, listener);
    }

    public void showIntentPicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                 final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.intentList = list;
        showIdNamePicker(EPickerType.PICK_INTENT, curEntity, listener);
    }

    private void postRequest(final int pickType, final IdNamePickerEntity curEntity,
                             final EPickerEntityListener<IdNamePickerEntity> listener) {
        postRequest(pickType, curEntity, null, listener);
    }

    public void showOrderStatePicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                     final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.orderStateList = list;
        showIdNamePicker(EPickerType.PICK_ORDER_STATE_LIST, curEntity, listener);
    }

    public void showCheckStatePicker(List<IdNamePickerEntity> list, IdNamePickerEntity curEntity,
                                     final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.orderCheckStateList = list;
        showIdNamePicker(EPickerType.PICK_CHECK_STATE_LIST, curEntity, listener);
    }

    private void postRequest(final int pickType, final IdNamePickerEntity curEntity, Map<String, String> paramMap,
                             final EPickerEntityListener<IdNamePickerEntity> listener) {

        List<IdNamePickerEntity> entityList = null;
        String url = EAppUtil.getApiHost();
        if (paramMap == null) paramMap = new HashMap<>();
        if (EPickerType.PICK_ALL_PERSON == pickType) {
            entityList = personList;
        } else if (EPickerType.PICK_CLASS_ROOM == pickType) {
            paramMap.put("action", "gzaClassRoom");
            paramMap.put("school_id", LocalCacheUtil.getSchoolId());
            entityList = classRoomList;
        } else if (EPickerType.PICK_VIP_STUDENT == pickType) {
//            url += Api.API_STU_VIP_CARD;
            entityList = stuVipList;
            paramMap.put("action", "memberProductList");
            paramMap.put("eid", LocalCacheUtil.getUid());
        } else if (EPickerType.PICK_CLASS == pickType) {
//            url += Api.API_CLASS_PICK;
            entityList = classList;
        } else if (EPickerType.PICK_TEACHER_CLASS == pickType) {
            //           url += Api.API_TEACHER_CLASS_PICK;
            entityList = teaClassList;
        } else if (EPickerType.PICK_TEACHER_LEAVE_TYPE == pickType) {
            //           url += Api.API_TEACHER_LEAVE_TYPE_PICK;
            entityList = teaLeaveTypeList;
        } else if (EPickerType.PICK_TEMP_TEACHER == pickType) {
            //           url += Api.API_TEMP_TEACHER_PICK;
            entityList = teaTempList;
        } else if (EPickerType.PICK_FILE == pickType) {
            //           url += Api.API_FILE_PICK;
            entityList = fileList;
        } else if (EPickerType.PICK_CONSULTANT == pickType) {
            entityList = ctList;
            paramMap.put("action", "headSaleList");
            paramMap.put("eid", LocalCacheUtil.getUid());
        } else if (EPickerType.PICK_COURSE_TYPE == pickType) {
//            url += Api.API_COURSE_TYPE;
            entityList = courseList;
        } else if (EPickerType.PICK_AGE_RANGE == pickType) {
            //           url += Api.API_AGE_RANGE;
            entityList = ageList;
            paramMap.put("action", "stageList");
            paramMap.put("eid", LocalCacheUtil.getUid());
        } else if (EPickerType.PICK_OPEN_DATE == pickType) {
            entityList = openDateList;
        } else if (EPickerType.PICK_SCHOOL == pickType) {
            entityList = schoolList;
            paramMap.put("action", "schoolList");
            paramMap.put("eid", LocalCacheUtil.getUid());
        } else if (EPickerType.PICK_CLASS_TYPE == pickType) {
            entityList = classTypeList;
            paramMap.put("action", "teacherCourseTypeList");
            paramMap.put("eid", LocalCacheUtil.getUid());
        } else if (EPickerType.PICK_CLASS_STATE == pickType) {
            entityList = classStateList;
            paramMap.put("action", "teacherCoursestageList");
            paramMap.put("eid", LocalCacheUtil.getUid());
        } else if (EPickerType.PICK_CLASS_WARE == pickType) {
            entityList = classWareList;
            paramMap.put("action", "gzaTrialware");
        } else if (EPickerType.PICK_CLASS_DATE == pickType) {
            entityList = classDateList;
            paramMap.put("action", "gzaStartTime");
        } else if (EPickerType.PICK_STUDENT_LIST == pickType) {
            entityList = studentList;
            paramMap.put("action", "schoolTeacherAndGzaList");
            paramMap.put("school_id", LocalCacheUtil.getSchoolId());
        }

        if (EmptyUtil.isEmpty(entityList) || EPickerType.PICK_FILE == pickType) {

            HttpUtils.getInstance().postFrom(url, paramMap, new NewEListCallback<IdNamePickerEntity>(mContext) {
                @Override
                protected void onSuccess(List<IdNamePickerEntity> data, String msg) {
                    String tipMsg = "";
                    if (EPickerType.PICK_ALL_PERSON == pickType) {
                        personList = data;
                        tipMsg = "无负责人可选";
                    } else if (EPickerType.PICK_CLASS_ROOM == pickType) {
                        classRoomList = data;
                        tipMsg = "无教室可选";
                    } else if (EPickerType.PICK_VIP_STUDENT == pickType) {
                        stuVipList = data;
                        tipMsg = "无会员卡可选";
                    } else if (EPickerType.PICK_CLASS == pickType) {
                        classList = data;
                        tipMsg = "无班级可选";
                    } else if (EPickerType.PICK_TEACHER_CLASS == pickType) {
                        teaClassList = data;
                        tipMsg = "无班级可选";
                    } else if (EPickerType.PICK_TEACHER_LEAVE_TYPE == pickType) {
                        teaLeaveTypeList = data;
                        tipMsg = "无请假类型可选";
                    } else if (EPickerType.PICK_TEMP_TEACHER == pickType) {
                        teaTempList = data;
                        tipMsg = "无代课老师可选";
                    } else if (EPickerType.PICK_FILE == pickType) {
                        fileList = data;
                        tipMsg = "无课件可选";
                    } else if (EPickerType.PICK_CONSULTANT == pickType) {
                        ctList = data;
                        tipMsg = "无课程顾问可选";
                    } else if (EPickerType.PICK_COURSE_TYPE == pickType) {
                        courseList = data;
                        tipMsg = "无课程类型可选";
                    } else if (EPickerType.PICK_AGE_RANGE == pickType) {
                        ageList = data;
                        tipMsg = "无年龄区间可选";
                    } else if (EPickerType.PICK_OPEN_DATE == pickType) {
                        openDateList = data;
                        tipMsg = "无开学日期可选";
                    } else if (EPickerType.PICK_SCHOOL == pickType) {
                        schoolList = data;
                        tipMsg = "无开学日期可选";
                    } else if (EPickerType.PICK_CLASS_TYPE == pickType) {
                        classTypeList = data;
                        tipMsg = "无课程类型";
                    } else if (EPickerType.PICK_CLASS_STATE == pickType) {
                        classStateList = data;
                        tipMsg = "无课程阶段";
                    } else if (EPickerType.PICK_CLASS_WARE == pickType) {
                        classWareList = data;
                        tipMsg = "无课件";
                    } else if (EPickerType.PICK_CLASS_NUMBER == pickType) {
                        classNumberList = data;
                        tipMsg = "无节数";
                    } else if (EPickerType.PICK_CLASS_DATE == pickType) {
                        classDateList = data;
                        tipMsg = "无节数";
                    } else if (EPickerType.PICK_STUDENT_LIST == pickType) {
                        studentList = data;
                        tipMsg = "无数据";
                    }

                    if (data != null && data.size() > 0) {
                        // showDialog
                        showIdNamePicker(pickType, curEntity, listener);
                    } else {
                        if (!TextUtils.isEmpty(tipMsg)) ToastUtil.show(mContext, tipMsg);
                    }
                }
            });
        } else {
            showIdNamePicker(pickType, curEntity, listener);
        }

    }

    private void showIdNamePicker(int pickType, IdNamePickerEntity curEntity, final EPickerEntityListener<IdNamePickerEntity> listener) {
        this.mPicType = pickType;

        List<IdNamePickerEntity> entityList = new ArrayList<>();
        if (EPickerType.PICK_ALL_PERSON == pickType) {
            entityList = personList;
        } else if (EPickerType.PICK_CLASS_ROOM == pickType) {
            entityList = classRoomList;
        } else if (EPickerType.PICK_CLASS_TYPE == pickType) {
            entityList = classTypeList;
        } else if (EPickerType.PICK_WEEK_DAY == pickType) {
            entityList = weekDayList;
        } else if (EPickerType.PICK_VIP_STUDENT == pickType) {
            entityList = stuVipList;
        } else if (EPickerType.PICK_CLASS == pickType) {
            entityList = classList;
        } else if (EPickerType.PICK_CLUE_FROM == pickType) {
            entityList = clueFromList;
        } else if (EPickerType.PICK_TEACHER_CLASS == pickType) {
            entityList = teaClassList;
        } else if (EPickerType.PICK_TEACHER_LEAVE_TYPE == pickType) {
            entityList = teaLeaveTypeList;
        } else if (EPickerType.PICK_TEMP_TEACHER == pickType) {
            entityList = teaTempList;
        } else if (EPickerType.PICK_VISIT_WISH == pickType) {
            entityList = wishList;
        } else if (EPickerType.PICK_FILE == pickType) {
            entityList = fileList;
        } else if (EPickerType.PICK_CLASS_ATTEND_STATE == pickType) {
            entityList = classStateList;
        } else if (EPickerType.PICK_CONSULTANT == pickType) {
            entityList = ctList;
        } else if (EPickerType.PICK_COURSE_TYPE == pickType) {
            entityList = courseList;
        } else if (EPickerType.PICK_AGE_RANGE == pickType) {
            entityList = ageList;
        } else if (EPickerType.PICK_OPEN_DATE == pickType) {
            entityList = openDateList;
        } else if (EPickerType.PICK_CLUE_STATE == pickType) {
            entityList = clueStateList;
        } else if (EPickerType.PICK_SCHOOL == pickType) {
            entityList = schoolList;
        } else if (EPickerType.PICK_INTENT == pickType) {
            entityList = intentList;
        } else if (EPickerType.PICK_CLASS_STATE == pickType) {
            entityList = classStateList;
        } else if (EPickerType.PICK_CLASS_WARE == pickType) {
            entityList = classWareList;
        } else if (EPickerType.PICK_CLASS_KIND == pickType) {
            entityList = classKindList;
        } else if (EPickerType.PICK_CLASS_NUMBER == pickType) {
            entityList = classNumberList;
        } else if (EPickerType.PICK_CLASS_DATE == pickType) {
            entityList = classDateList;
        } else if (EPickerType.PICK_CLASS_TEMP == pickType) {
            entityList = classTempList;
        } else if (EPickerType.PICK_STUDENT_LIST == pickType) {
            entityList = studentList;
        } else if (EPickerType.PICK_ORDER_STATE_LIST == pickType) {
            entityList = orderStateList;
        } else if (EPickerType.PICK_CHECK_STATE_LIST == pickType) {
            entityList = orderCheckStateList;
        } else if (EPickerType.PICK_CUSTOM == pickType) {
            entityList = customList;
        }

        final List<IdNamePickerEntity> finalEntityList = entityList;

        OptionsPickerView<IdNamePickerEntity> idNamePicker = new OptionsPickerBuilder(mContext, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {

                if (listener != null) {
                    IdNamePickerEntity entity = finalEntityList.get(options1);
                    listener.onSelectItem(mPicType, entity);
                }
            }
        }).setCancelColor(Color.BLACK)
                .setSubmitColor(Color.BLACK)
                .setTitleBgColor(Color.WHITE)
                .build();


        if (entityList != null) {
            idNamePicker.setPicker(entityList);

            int pointIndex = 0;
            boolean exist = entityList.contains(curEntity);
            if (exist) pointIndex = entityList.indexOf(curEntity);
            else if (curEntity != null) {
                String curId = curEntity.getId();
                for (int i = 0; i < entityList.size(); i++) {
                    IdNamePickerEntity entity = entityList.get(i);
                    if (EmptyUtil.isEmpty(curId)) break;
                    if (curId.equalsIgnoreCase(entity.getId())) {
                        pointIndex = i;
                        break;
                    }
                }
            }


            idNamePicker.setSelectOptions(pointIndex);
            idNamePicker.show();
        }

        KeyboardUtil.hide(mContext);
    }

    public List<IdNamePickerEntity> getTeacherList() {
        return studentList;
    }

}
